<?php
/**
 * Description of LessThan
 *
 * @author      Maciej Zawieja.
 * @link        http://akvus.pl
 * @package     Akvus Framework.
 * @subpackage  Libraries.
 * @copyright   2011 All rights reserved for Maciej Zawieja.
 * @version     1.0.0 - 19.08.2011 (Framework 1.3)
 */
class Type implements iValidation {

    const PARAMS_QUANTITY = 1;

    private $type;

    public function isValid( $text ) {
        if ( is_string($text) )
            if ( $type & Validation::TYPE_STRING != Validation::TYPE_STRING )
                throw new ValidationException ('Value has invalid (string) type.', ValidationException::INVALID_TYPE);

        if( is_integer($text) )
            if( $type & Validation::TYPE_INT != Validation::TYPE_INT )
                throw new ValidationException ('Value has invalid (integer) type.', ValidationException::INVALID_TYPE);

        if( is_float($text) or is_double($text) )
            if( $type & Validation::TYPE_FLOAT != Validation::TYPE_FLOAT )
                throw new ValidationException ('Value has invalid (float) type.', ValidationException::INVALID_TYPE);

        if( is_bool($text) )
            if( $type & Validation::TYPE_BOOL != Validation::TYPE_BOOL )
                throw new ValidationException ('Value has invalid (boolean) type.', ValidationException::INVALID_TYPE);

        if( is_array($text) )
            if( $type & Validation::TYPE_ARRAY != Validation::TYPE_ARRAY )
                throw new ValidationException ('Value has invalid (array) type.', ValidationException::INVALID_TYPE);
    }

    public function setParams( array &$params ) {
        if ( count($params) < self::PARAMS_QUANTITY )
                throw new ProgrammerException ('Too less params for RegEx validation.', 0);

        $this->type = $params[0];
    }

    function Type( $type = null )
    {
        if ($type === null) return $this->type;
        $this->type = $type;
        return $this;
    }
}